package com.xique.park.service.service.impl;

import java.util.List;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xique.common.core.utils.DateUtils;
import com.xique.common.datascope.annotation.NeedSetDictLabel;
import com.xique.common.datascope.annotation.NeedSetFieldValue;
import com.xique.park.bean.dto.ParkLaneStatisticsDto;
import com.xique.park.bean.vo.client.ClientLaneVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.xique.park.mapper.ParkLaneMapper;
import com.xique.park.bean.domain.ParkLane;
import com.xique.park.service.service.IParkLaneService;

/**
 * 通道Service业务层处理
 *
 * @author xique
 * @date 2021-12-09
 */
@Service
public class ParkLaneServiceImpl implements IParkLaneService {

    @Autowired
    private ParkLaneMapper parkLaneMapper;

    /**
     * 查询通道
     *
     * @param id 通道ID
     * @return 通道
     */
    @Override
    @NeedSetFieldValue
    @NeedSetDictLabel
    public ParkLane selectParkLaneById(Long id) {
        return parkLaneMapper.selectById(id);
    }

    /**
     * 查询通道列表
     *
     * @param parkLane 通道
     * @return 通道
     */
    @Override
    public List<ParkLane> selectParkLaneList(ParkLane parkLane) {
        QueryWrapper<ParkLane> wrapper = new QueryWrapper<>();
        wrapper.eq("park_id", parkLane.getParkId());
        return parkLaneMapper.selectList(wrapper);
    }

    /**
     * 新增通道
     *
     * @param parkLane 通道
     * @return 结果
     */
    @Override
    public int insertParkLane(ParkLane parkLane) {
        parkLane.setCreateTime(DateUtils.getNowDate());
        return parkLaneMapper.insert(parkLane);
    }

    /**
     * 修改通道
     *
     * @param parkLane 通道
     * @return 结果
     */
    @Override
    public int updateParkLane(ParkLane parkLane) {
        parkLane.setUpdateTime(DateUtils.getNowDate());
        return parkLaneMapper.updateById(parkLane);
    }

    /**
     * 批量删除通道
     *
     * @param ids 需要删除的通道ID
     * @return 结果
     */
    @Override
    public int deleteParkLaneByIds(List<Long> ids) {
        return parkLaneMapper.deleteBatchIds(ids);
    }

    /**
     * 删除通道信息
     *
     * @param id 通道ID
     * @return 结果
     */
    @Override
    public int deleteParkLaneById(Long id) {
        return parkLaneMapper.deleteById(id);
    }

    @Override
    public ParkLaneStatisticsDto selectOnLineStatus(Integer province, Integer city, Integer district,
                                                    Long deptId, Long parkInfoId) {
        return parkLaneMapper.selectOnLineStatus(province, city, district, deptId, parkInfoId);
    }

    @Override
    @NeedSetDictLabel
    public List<ClientLaneVo> selectParkLaneByClient(Long parkId, String clientId) {
        return parkLaneMapper.selectParkLaneByClient(parkId, clientId);
    }

    @Override
    public List<ParkLane> selectParkLaneByParkId(Long parkId, String laneType) {
        LambdaQueryWrapper<ParkLane> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(ParkLane::getParkId, parkId);
        queryWrapper.eq(StrUtil.isNotBlank(laneType), ParkLane::getLaneType, laneType);
        return parkLaneMapper.selectList(queryWrapper);
    }

}
